<template>
    <duv>
        <avue-form ref="form" :option="formOption" v-model="form"></avue-form>
        <el-row :gutter="20">
            <el-col :span="12">
                <div>诊断报告</div>
                <el-divider></el-divider>
                <avue-crud ref="crud" :loading="loading" :option="option" @on-load="onLoad" :data="data"
                    @selection-change="selectionChange"></avue-crud>
            </el-col>
            <el-col :span="12">
                <div>诊断结果</div>
                <el-divider></el-divider>
                <avue-crud :option="resultOption" :data="resultData"></avue-crud>
            </el-col>
        </el-row>
    </duv>
</template>
<script>
import { getDiagnoseList, diagnostic } from "@/api/infoManagement/patientFile";

export default {
    props: {
        reportTypeId: {
            type: String,
            default: ''
        },
        patientId: {
            type: String,
            default: ''
        }
    },
    data() {
        return {
            selectionList: [],
            loading: false,
            form: {
                ruleId: ''
            },
            formOption: {
                submitBtn: false,
                emptyBtn: false,
                column: [
                    {
                        label: "规则名称",
                        prop: "ruleId",
                        hide: true,
                        type: "select",
                        dicUrl: '/api/blade-platform/rule/ruleArray',
                        rules: [{
                            required: false,
                            message: "请选择规则名称",
                            trigger: "change"
                        }]
                    },
                ]
            },
            data: [],
            option: {
                index: true,
                selection: true,
                addBtn: false,
                addRowBtn: false,
                cellBtn: true,
                menuWidth: 250,
                menu: false,
                columnBtn: false,
                height: '250',
                column: [{
                    label: '检查日期',
                    prop: 'checkDate',
                    cell: true,
                    rules: [
                        {
                            required: true,
                            message: '请输入',
                            trigger: 'blur'
                        }
                    ]
                },
                {
                    label: '报告类型',
                    prop: 'type',
                    cell: true,
                    rules: [
                        {
                            required: true,
                            message: '请输入',
                            trigger: 'blur'
                        }
                    ]
                },
                {
                    label: '就诊医院',
                    prop: 'deptName',
                    cell: true,
                    rules: [
                        {
                            required: true,
                            message: '请输入',
                            trigger: 'blur'
                        }
                    ]
                },
                {
                    label: '添加时间',
                    prop: 'createTime',
                    cell: true,
                    rules: [
                        {
                            required: true,
                            message: '请输入',
                            trigger: 'blur'
                        }
                    ]
                },


                ]
            },
            resultData: [],
            resultOption: {
                index: true,
                selection: true,
                addBtn: false,
                addRowBtn: false,
                cellBtn: true,
                menuWidth: 250,
                menu: false,
                columnBtn: false,
                height: '250',
                column: [{
                    label: '规则名称',
                    prop: 'ruleName',
                    cell: true,
                },
                {
                    label: '诊断结果',
                    prop: 'value',
                    cell: true,
                    formatter(row, value) {
                        if (value) {
                            return '成功'
                        } else {
                            return '失败'
                        }
                    }
                },
                ]
            }
        }
    },
    methods: {
        selectionChange(list) {
            this.selectionList = list
        },
        diagnose() {
            debugger
            const arr = this.selectionList.map((element) => {
                return element.id
            })
            if (arr.length == 0) {
                this.$message.warning('最少选择一条诊断报告')
                return
            }
            const checkIds = arr.join(',')
            diagnostic({
                patientId: this.patientId,
                ruleId: this.form.ruleId,
                checkIds
            }).then((res) => {
                const data = res.data.data
                this.resultData = data
            })
        },
        selectionClear() {
            this.selectionList = [];
            this.$refs.crud.toggleSelection();
        },
        onLoad(page, params = {}) {
            this.loading = true
            getDiagnoseList({
                patientId: this.patientId
            }).then((res) => {
                this.loading = false;
                const data = res.data.data;
                // this.page.total = data.total;
                this.data = data.records;
                this.selectionClear();
            })
        },
        rowSave(form, done) {
            // this.$message.success(
            //     '新增数据' + JSON.stringify(form)
            // )
            done()
        },
        addUpdate(form, index, done, loading) {
            // this.$message.success('模拟网络请求')
            setTimeout(() => {
                // this.$message.success('关闭按钮等待')
                loading()
            }, 1000)
            setTimeout(() => {
                // this.$message.success(
                //     '编辑数据' + JSON.stringify(form) + '数据序号' + index
                // )
                done()
            }, 2000)
        }
    }
}
</script>